import os
import zipfile


def zip_dir(to_zip_dir, save_dir, zip_id):
    """
    zip压缩目标目录下的所有文件
    :param to_zip_dir:
    :param save_dir:
    :param zip_id:
    :return:
    """
    ziped_path = os.path.join(save_dir, f"report_img_{zip_id}.zip")
    zip_robot = zipfile.ZipFile(ziped_path, "w")

    for a, b, files in os.walk(to_zip_dir):
        for f in files:
            to_zip_file = os.path.join(to_zip_dir, f)
            zip_robot.write(to_zip_file, os.path.basename(to_zip_file))
        break

    zip_robot.close()
    return ziped_path
